package com.zhijian.medical.controller;

import com.zhijian.medical.annotation.CurrentUser;
import com.zhijian.medical.api.CommonResult;
import com.zhijian.medical.entity.dto.PersonDto;
import com.zhijian.medical.entity.po.ExperimentFish;
import com.zhijian.medical.entity.vo.request.ExperimentFishSearchVo;
import com.zhijian.medical.entity.vo.response.ExperimentFishDeviceVo;
import com.zhijian.medical.entity.vo.response.ExperimentProcessSampleVo;
import com.zhijian.medical.service.FishService;
import com.zhijian.medical.service.ExperimentProcessSampleService;
import com.zhijian.medical.util.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;
import java.util.List;

@Slf4j
@RestController
@Api(tags = "【FISH实验】")
@RequestMapping("/fish")
public class FishController {

    @Autowired
    private ExperimentProcessSampleService processSampleService;
    @Autowired
    private FishService fishService;

    @GetMapping("/pathology/list")
    @ApiOperation("病理列表")
    public CommonResult<List<ExperimentProcessSampleVo>> pathologyList(@RequestParam(required = false) Byte mainType, @RequestParam(required = false) Byte status) {

        return CommonResult.success(processSampleService.fishSampleList());
    }


    @PostMapping("/experiment")
    @ApiOperation("创建实验")
    public CommonResult<Boolean> create(@CurrentUser @ApiIgnore PersonDto personDto, @RequestBody ExperimentFish experimentFish) {
        experimentFish.setPersonDto(personDto);
        return CommonResult.success(fishService.create(experimentFish) > 0);
    }

    @GetMapping("/experiment/{id}")
    @ApiOperation("实验详情")
    public CommonResult<ExperimentFish> detail(@PathVariable("id") Long id) {
        return CommonResult.success(fishService.detail(id));
    }


    @PutMapping("/experiment/{id}")
    @ApiOperation("修改实验")
    public CommonResult<Boolean> update(@PathVariable("id") Long id, @RequestBody ExperimentFish experimentFish) {
        experimentFish.setId(id);
        return CommonResult.success(fishService.update(experimentFish));
    }


    @DeleteMapping("/experiment/{id}")
    @ApiOperation("删除实验")
    public CommonResult<Boolean> delete(@PathVariable("id") Long id) {
        return CommonResult.success(fishService.delete(id));
    }

    @PostMapping("/experiment/list")
    @ApiOperation("分页查询")
    public CommonResult<Page<ExperimentFish>> list(@RequestBody ExperimentFishSearchVo param) {
        return CommonResult.success(fishService.selectPage(param));
    }

    @PostMapping("/experiment/device")
    @ApiOperation("FISH实验设备")
    public CommonResult<ExperimentFishDeviceVo> devices() {
        return CommonResult.success(fishService.devices());
    }

}
